/*
 * ConnectorBD.java
 *
 * Created on 10 de enero de 2004, 12:44 PM
 */

package com.puj.bdutils;

import com.rp.database.*;
/** 
 *
 * @author  eamessa
 */
public class ConnectorBD {
    

	public final static String key = "People";
        public final static String keyPortal = "Portal";
        public final static String keyPresu = "Consulta_Presu"; 
        
        
	//public final static String pathSuffix = "\\com\\puj\\config\\config.properties";
	protected static ConnectionManager manager = null;
      	protected static ConnectionManager managerPortal = null;
       	protected static ConnectionManager managerPresu = null;
    
	public static PooledConnection getConnection (String pathPrefix) throws java.sql.SQLException
	{
             String fileSeparator =System.getProperty("file.separator");   
             System.out.println("el path es " + pathPrefix);
             PooledConnection pc;
              
		if (manager == null)
		{
                    System.out.println(pathPrefix+fileSeparator+"com"+fileSeparator+"puj"+fileSeparator+"config"+fileSeparator+"config.properties");
                    String finalPath=pathPrefix+fileSeparator+"com"+fileSeparator+"puj"+fileSeparator+"config"+fileSeparator+"config.properties";	
                    init(finalPath);	
                    
		}
              
		pc = manager.getConnection();
                if(pc==null)
                {
                    throw new java.sql.SQLException("Error No se pudo Obtener Conexión desde el Pool");
                }
                return pc;
	}
	
	protected static void init (String path) throws java.sql.SQLException
	{
               // System.out.println("Inicializando con "+path);
		manager = BrokerHandle.getConnectionManagerBroker().getConnectionManager(key, path);
	}     
        
        
  // Inicia metodos para coneccion con el Portal
      	public static PooledConnection getConnectionPortal (String pathPrefix) throws java.sql.SQLException
	{
             String fileSeparator =System.getProperty("file.separator");   
             PooledConnection pcPortal;
              
		if (managerPortal == null)
		{
                    String finalPath=pathPrefix+fileSeparator+"com"+fileSeparator+"puj"+fileSeparator+"config"+fileSeparator+"config.properties";	
                    initPortal(finalPath);	
		}
              
		pcPortal = managerPortal.getConnection();
                if(pcPortal==null)
                {
                    throw new java.sql.SQLException("Error No se pudo Obtener Conexión desde el Pool para el Portal");
                }
                return pcPortal;
	} 

      	protected static void initPortal (String path) throws java.sql.SQLException
	{
             //System.out.println("Inicializando con "+path);
	     managerPortal = BrokerHandle.getConnectionManagerBroker().getConnectionManager(keyPortal, path);
	}     

     // Inicia metodos para coneccion con el Portal
      	public static PooledConnection getConnectionPresu (String pathPrefix) throws java.sql.SQLException
	{
             String fileSeparator =System.getProperty("file.separator");   
             PooledConnection pcPresu;
              
		if (managerPresu == null)
		{
                    String finalPath=pathPrefix+fileSeparator+"com"+fileSeparator+"puj"+fileSeparator+"config"+fileSeparator+"config.properties";	
                    initPresu(finalPath);	
		}
              
		pcPresu = managerPresu.getConnection();
                //System.out.println("Inicializando con "+pcPresu);
                if(pcPresu==null)
                {
                    throw new java.sql.SQLException("Error No se pudo Obtener Conexión desde el Pool para el Portal de Presupeusto");
                }
                return pcPresu;
	} 

      	protected static void initPresu (String path) throws java.sql.SQLException
	{
             System.out.println("Inicializando con "+keyPresu);
	     managerPresu = BrokerHandle.getConnectionManagerBroker().getConnectionManager(keyPresu, path);
	}     

        
}// Fin Principal
